package com.xiaoye.qbproject.controller.mq;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xiaoye.qbproject.controller.base.BaseController;
import com.xiaoye.qbproject.domain.AjaxResult;
import com.xiaoye.qbproject.domain.MqConfig;
import com.xiaoye.qbproject.service.MqConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mqConfig")
public class MqConfigController extends BaseController {
    @Autowired
    private MqConfigService mqConfigService;

    @GetMapping
    public AjaxResult getDefaultMqConfig() {
        return AjaxResult.success(mqConfigService.list(Wrappers.lambdaQuery(MqConfig.class).last("limit 1")));
    }

    @PostMapping
    public AjaxResult saveMqConfig(@RequestBody MqConfig mqConfig) {

        mqConfigService.addMq(mqConfig);
        return AjaxResult.success();
    }

    @PutMapping
    public AjaxResult updateMqConfig(@RequestBody MqConfig mqConfig) {
        mqConfigService.editMqConfig(mqConfig);
        return AjaxResult.success();
    }
}